package com.heng.futureDemo;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class ACompletableFutureAPIDemo9 {
    public static void main(String[] args) {
        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            try {TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {e.printStackTrace();}
            return "abc";
        });
//        try {TimeUnit.SECONDS.sleep(3);} catch (InterruptedException e) {e.printStackTrace();}

        System.out.println(completableFuture.getNow("xxx"));//getOrDefault()
//        System.out.println(completableFuture.get(2L,TimeUnit.SECONDS));

        //是否打断get,然后获取指定的value值
        System.out.println(completableFuture.complete("completeValue") + "\t" + completableFuture.join());

    }
}